Public Class Parasite
    Protected _parasite_id As Integer
    Protected _parasite_name_tha As String
    Protected _parasite_name_eng As String
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property parasite_id() As Integer
        Get
            Return _parasite_id
        End Get
        Set(ByVal value As Integer)
            _parasite_id = value
        End Set
    End Property

    Public Property parasite_name_tha() As String
        Get
            Return _parasite_name_tha
        End Get
        Set(ByVal value As String)
            _parasite_name_tha = value
        End Set
    End Property

    Public Property parasite_name_eng() As String
        Get
            Return _parasite_name_eng
        End Get
        Set(ByVal value As String)
            _parasite_name_eng = value
        End Set
    End Property

    Public Function getParasite() As DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_Parasite"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "Parasite")

        Return objDs
    End Function

    Protected Function getsParasite() As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_Parasite"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "Parasite")

        For Each objDr As System.Data.DataRow In objDs.Tables("Parasite").Rows
            Dim obj As Parasite = New Parasite
            obj.parasite_id = objDr.Item("parasite_id").ToString()
            obj.parasite_name_tha = objDr.Item("parasite_name_tha").ToString()
            obj.parasite_name_eng = objDr.Item("parasite_name_eng").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _parasite_id = _Data(_DataCurrent).parasite_id
            _parasite_name_tha = _Data(_DataCurrent).parasite_name_tha
            _parasite_name_eng = _Data(_DataCurrent).parasite_name_eng
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Sub LoadParasite()
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsParasite()
    End Sub

    Public Function insertParasite(ByVal inParasite As Parasite) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_Parasite"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inParasiteID", _
                Utilities.SendToDatabase(inParasite.parasite_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inParasiteNameTha", _
                Utilities.SendToDatabase(inParasite.parasite_name_tha))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inParasiteNameEng", _
                Utilities.SendToDatabase(inParasite.parasite_name_eng))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function updateParasite(ByVal inParasite As Parasite) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_UPDATE_Parasite"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inParasiteID", _
                Utilities.SendToDatabase(inParasite.parasite_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inParasiteNameTha", _
                Utilities.SendToDatabase(inParasite.parasite_name_tha))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inParasiteNameEng", _
                Utilities.SendToDatabase(inParasite.parasite_name_eng))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function deleteParasite(ByVal inParasite As Parasite) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_DELETE_Parasite"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inParasiteID", _
                Utilities.SendToDatabase(inParasite.parasite_id))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Shared Function getParasiteByEngName(ByVal parasiteEngName As String) As Parasite
        Dim outResult As New Parasite()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_ParasiteByEngName"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inParasiteEngName", parasiteEngName)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "Parasite")

        For Each objDr As System.Data.DataRow In objDs.Tables("Parasite").Rows
            outResult.parasite_id = objDr.Item("parasite_id").ToString()
            outResult.parasite_name_tha = objDr.Item("parasite_name_tha").ToString()
            outResult.parasite_name_eng = objDr.Item("parasite_name_eng").ToString()
        Next

        Return outResult
    End Function
End Class
